<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        function getData(url) {
            // 返回Promise对象
            return new Promise((resolve, reject) => {
                //1.创建对象
                const xhr = new XMLHttpRequest()
                    //2.初始化 Get请求
                xhr.open('GET', url)
                    //3.发送
                xhr.send()
                    //4.事件绑定
                xhr.onreadystatechange = function() {
                    //状态判断
                    if (xhr.readyState === 4) {
                        // 请求成功与失败处理
                        if (xhr.status >= 200 && xhr.status < 300) {
                            resolve(xhr.responseText)
                        } else {
                            reject(xhr.responseText)
                        }
                    }
                }
            })
        }
        // 使用async/await处理
        async function $http() {
            let res = await getData(' https://test.galayun.com/smallprogapi/test/GetXiaolai')
            console.log(res)
        }
        $http();
    </script>
</body>

</html>